<template>
  <!-- <div v-if="orgCode === ''">
    <div class="my-code">点击组织机构查看用户</div>
  </div>-->
  <div>
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      :sup_this="sup_this"
      :data="data.rtnList"
      :multi-select="false"
      :show-page="false"
      :all-define-columns="['phone','email','mgrAccount','userStatus','jobName','createDate']"
      grid-id="userOrgSetListGridId"
      height="300px">
      <el-table-column v-if="checkPermission(['SYS_ADMIN','COMMON_ADMIN','ORGSET_ALL','ORGSET_CREATE','ORGSET_DELETE'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="setUserInfo(scope.row)"/>
          <el-popover
            v-if="orgCode != ''"
            :ref="scope.row.relId"
            placement="top"
            width="180">
            <p>确定要移除吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.relId].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.relId)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="userAccount" label="用户账号"/>
      <el-table-column prop="userName" label="名称" width="150px" />
      <el-table-column slot="mgrAccount" prop="mgrAccount" label="上级" width="100px" />
      <el-table-column slot="phone" prop="phone" label="电话" width="200px" />
      <el-table-column slot="email" prop="email" label="邮件" width="200px" />
      <el-table-column slot="jobName" prop="jobName" label="职务" width="100px" />
      <el-table-column slot="userStatus" prop="userStatus" label="用户状态" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.user_status" :key="item.id">
            <el-tag v-if="scope.row.userStatus.toString() === item.dictCode" :type="scope.row.userStatus === 'UNLOCK' ? '' : 'info'">{{ item.dictName }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column slot="createDate" prop="createDate" label="创建日期" width="200px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate) }}</span>
        </template>
      </el-table-column>
    </DataGridTable>
    <user-info-set ref="UserInfoSet" :sup_this="cur_this" />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { deleteUserOrgSet } from '@/api/system/orgSet'
import { parseTime } from '@/utils/index'
import { getUserInfo } from '@/utils/auth'
import { findUserByOrgCodeUrl, findUserByCpyCodeUrl } from '@/api/user'
import UserInfoSet from './userInfoSet'

export default {
  components: { UserInfoSet },
  mixins: [initData],
  dictTypes: ['user_status'],
  props: {
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      delLoading: false,
      orgCode: null,
      cur_this: this
    }
  },
  created() {
    // this.url = findUserByOrgCodeUrl()
    /* this.$nextTick(() => {
      this.init()
    })*/
  },
  methods: {
    parseTime,
    checkPermission,
    loadUserData() {
      this.url = findUserByOrgCodeUrl()
      if (!this.orgCode) {
        this.url = findUserByCpyCodeUrl()
      }
      this.init()
    },
    async beforeInit() {
      this.paramBean.cpyCode = getUserInfo().cpyCode
      this.paramBean.orgCode = this.orgCode
      return true
    },
    setUserInfo(userRow) {
      const _this = this.$refs.UserInfoSet
      _this.init(userRow)
      _this.dialog = true
    },
    subDelete(relId) {
      this.delLoading = true
      const data = { userOrgSetVOList: [{ id: relId }] }
      deleteUserOrgSet(data).then(res => {
        this.delLoading = false
        this.$refs[relId].doClose()
        this.init()
      }).catch(err => {
        this.delLoading = false
        this.$refs[relId].doClose()
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>
  .my-code{
    padding: 15px;
    line-height: 20px;
    border-left: 3px solid #ddd;
    color: #333;
    font-family: Courier New;
    font-size: 12px
  }
</style>
